﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;

namespace WFFS
{
    public partial class FrmZC : Form
    {
        private Form1 frmMain = null;  
        public FrmZC(Form1 _frm)
        {
            InitializeComponent();           
            frmMain = _frm;
        }

        private void FrmZC_Load(object sender, EventArgs e)
        {
            DirectoryInfo dir = new DirectoryInfo(Application.StartupPath + "\\pic\\");
            int i = 0;
            int j = 0;
            int k = 0;
            FileInfo[] fis = dir.GetFiles();
            for (int l = fis.Length - 1; l >= 0; l--)
            {
            //foreach (FileInfo d in dir.GetFiles())
            //{
                PictureBox pb = new PictureBox();
                Image img = new Bitmap(Application.StartupPath + "\\pic\\" + fis[l].Name);
                pb.Image = img;
                pb.SizeMode = PictureBoxSizeMode.StretchImage;
                pb.Name = fis[l].Name;
                pb.Size = new System.Drawing.Size(90, 72);
                pb.TabIndex = i;
                pb.TabStop = false;
                pb.Click += this.pic_Click;

                if (i  == 0)
                {
                    pb.Location = new Point(2, 6 + k * 90);
                    k++;
                    this.panelJC.Controls.Add(pb);
                }
                else
                {
                    pb.Location = new Point(2+i*90, 6);
                    this.panelJC.Controls.Add(pb);
                    j++;
                }

                Console.WriteLine(pb.Location.Y.ToString());
                i++;
            }
        }

        //概览图点击事件
        private void pic_Click(object sender, EventArgs e)
        {
            Control control = (Control)sender;
            Image img = new Bitmap(Application.StartupPath + "\\pic\\" + control.Name);
            drawingzc.Visible = true;
            if (drawingzc.Image != null)
            {
                drawingzc.Image.Dispose();
            }
            drawingzc.Image = img;
           // frmMain.drawingzc.SizeMode = frmMain.drawingzc.SizeMode;
        }

        private void FrmZC_FormClosed(object sender, FormClosedEventArgs e)
        {
            string x = this.Location.X.ToString();
            string y = this.Location.Y.ToString();
            WriteIniData("FrmZC", "X", x, Application.StartupPath + @"\WFFS.ini");
            WriteIniData("FrmZC", "Y", y, Application.StartupPath + @"\WFFS.ini");
        }
        public static bool WriteIniData(string Section, string Key, string Value, string iniFilePath)
        {
            if (File.Exists(iniFilePath))
            {
                long OpStation = WritePrivateProfileString(Section, Key, Value, iniFilePath);
                if (OpStation == 0)
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
            else
            {
                return false;
            }
        }
        [DllImport("kernel32")]
        private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
    }
}
